﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Text;
using System.Globalization;
using TanHungViet.Web.Models;
using TanHungViet.Helper;
using System.Net;
using System.Net.Mail;

namespace TanHungViet.Web.Controllers
{
    public class TanHungVietController : Controller
    {
        // ++Index
        public ActionResult Index()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentForHomePage(cultureInfo).OrderByDescending(b => b.ContentID);
                model = new PaginatedList<Content>(contents, 0, Constant.PageSize);
            }

            ViewData["ContentCode"] = "home-page";
            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangChu", new CultureInfo(cultureInfo));

            return View("ThietKe", model);
        }
        // --Index

        #region UserControl
        ////////////////////////////////////////////////////////////////////////////////////////////////  
        // ++ UserControl //////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////
        // ++ Menu Ngang
        public ActionResult MenuNgang()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            List<MenuItem> model = new List<MenuItem>();
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                MenuRepository menuRepository = new MenuRepository(entity);
                model = menuRepository.GetDynamicMenu(cultureInfo, false);
            }

            return View(model);
        }
        // -- Menu Ngang
       
        // ++ Menu Doc
        public ActionResult MenuDoc()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            List<MenuItem> model = new List<MenuItem>();
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                MenuRepository menuRepository = new MenuRepository(entity);
                model = menuRepository.GetDynamicMenu(cultureInfo, true);
            }

            return View(model);
        }
        // -- Menu Doc

        // ++ Noi Dung Ben Trai
        public ActionResult NoiDungBenTrai()
        {
             string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository=new ContentRepository (entity);
                model = contentRepository.GetContentByCode(Constant.CodeNoiDungBenTrai, cultureInfo);
            }

            return View(model);
        }
        // -- Noi Dung Ben Trai

        // ++ Thoi Gian Lam Viec
        public ActionResult ThoiGianLamViec()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(Constant.CodeNoiDungThoiGianLamViec, cultureInfo);
            }

            return View("NoiDungBenTrai", model);
        }
        // -- Thoi Gian Lam Viec

        // ++ Thoi Gian Lam Viec
        public ActionResult QuangCaoBenPhai()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(Constant.CodeNoiDungQuangCaoBenPhai, cultureInfo);
            }

            return View("NoiDungBenTrai", model);
        }
        // -- Thoi Gian Lam Viec
        ////////////////////////////////////////////////////////////////////////////////////////////////  
        // -- UserControl //////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////
        #endregion

        #region Du An va Chi Tiet Du An
        ////////////////////////////////////////////////////////////////////////////////////////////////  
        // ++ Du An va Chi Tiet Du An //////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult ThietKe(string code, int? page)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            string pageTitleDetail = string.Empty;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentByParentCode(code, cultureInfo);
                if (contents == null)
                    return RedirectToAction("Index");
                else
                    contents = contents.OrderByDescending(b => b.ContentID);
                model = new PaginatedList<Content>(contents, page - 1 ?? 0, Constant.PageSize);
                pageTitleDetail = contentRepository.GetFullContentByID(contentRepository.GetContentByCode(code).ContentID).ContentTitle;
            }

            ViewData["ContentCode"] = code;
            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangThietKe", new CultureInfo(cultureInfo)) + " - " + pageTitleDetail;
            return View(model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult ThiCong(string code, int? page)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            string pageTitleDetail = string.Empty;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentByParentCode(code, cultureInfo);
                if (contents == null)
                    return RedirectToAction("Index");
                else
                    contents = contents.OrderByDescending(b => b.ContentID);
                
                model = new PaginatedList<Content>(contents, page - 1 ?? 0, Constant.PageSize);
                pageTitleDetail = contentRepository.GetFullContentByID(contentRepository.GetContentByCode(code).ContentID).ContentTitle;
            }

            ViewData["ContentCode"] = code;
            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangThiCong", new CultureInfo(cultureInfo)) + " - " + pageTitleDetail;
            return View("ThietKe", model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult CungCapVLXD(string code, int? page)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            string pageTitleDetail = string.Empty;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentByParentCode(code, cultureInfo);
                if (contents == null)
                    return RedirectToAction("Index");
                else
                    contents = contents.OrderByDescending(b => b.ContentID);
                model = new PaginatedList<Content>(contents, page - 1 ?? 0, Constant.PageSize);
                pageTitleDetail = contentRepository.GetFullContentByID(contentRepository.GetContentByCode(code).ContentID).ContentTitle;
            }

            ViewData["ContentCode"] = code;
            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangCungCapVLXD", new CultureInfo(cultureInfo)) + " - " + pageTitleDetail;
            return View("ThietKe", model);
        }


        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult ChiTietDuAn(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangChiTietDuAn", new CultureInfo(cultureInfo));
            return View( model);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////  
        // -- Du An va Chi Tiet Du An //////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////
        #endregion

        #region Cac noi dung 1 bai viet
        ////////////////////////////////////////////////////////////////////////////////////////////////  
        // ++ Cac noi dung 1 bai viet //////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult GioiThieu(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangGioiThieu", new CultureInfo(cultureInfo));
            return View("ChiTietNoiDung", model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult TuyenDung()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode("tuyen-dung", cultureInfo);
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangTuyenDung", new CultureInfo(cultureInfo));
            return View("ChiTietNoiDung", model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult LienHe()
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode("lien-he", cultureInfo);
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangLienHe", new CultureInfo(cultureInfo));
            return View("ChiTietNoiDung", model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult DichVu(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangDichVu", new CultureInfo(cultureInfo));
            return View("ChiTietNoiDung", model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult BaoGia(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangBaoGia", new CultureInfo(cultureInfo));
            return View("ChiTietNoiDung", model);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////  
        // -- Cac noi dung 1 bai viet //////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////
        #endregion

        #region Sitemap
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult Sitemap()
        {
            List<MenuItem> model = new List<MenuItem>();
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                MenuRepository menuRepository = new MenuRepository(entity);
                string cultureInfo = "";
                model = menuRepository.GetDynamicMenu(cultureInfo, false);
                model.AddRange(menuRepository.GetDynamicMenu(cultureInfo, true));
            }

            return View(model);
        }
        #endregion

        #region Tin Tuc
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult TinTuc(string code, int? page)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentByParentCode(code, cultureInfo).OrderByDescending(b => b.ContentID);
                model = new PaginatedList<Content>(contents, page - 1 ?? 0, Constant.PageSize2);
                ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangTinTuc", new CultureInfo(cultureInfo))
                + " - " + contentRepository.GetContentByCode(code, cultureInfo).ContentTitle;
            }

            ViewData["ParentCode"] = code;
            return View(model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult ChiTietTinTuc(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
                var parent = contentRepository.GetParentByContentCode(code, cultureInfo);
                ViewData["ParentTitle"] = parent.ContentTitle;
                ViewData["ParentCode"] = parent.ContentCode;
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangChiTietTinTuc", new CultureInfo(cultureInfo));
            return View(model);
        }
        #endregion

        #region Tu Van
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult TuVan(string code, int? page)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentByParentCode(code, cultureInfo).OrderByDescending(b => b.ContentID);
                model = new PaginatedList<Content>(contents, page - 1 ?? 0, Constant.PageSize2);
                ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangTuVan", new CultureInfo(cultureInfo))
                + " - " + contentRepository.GetContentByCode(code, cultureInfo).ContentTitle;
            }

            ViewData["ParentCode"] = code;
            return View(model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult ChiTietTuVan(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
                var parent = contentRepository.GetParentByContentCode(code, cultureInfo);
                ViewData["ParentTitle"] = parent.ContentTitle;
                ViewData["ParentCode"] = parent.ContentCode;
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangChiTietTuVan", new CultureInfo(cultureInfo));
            return View(model);
        }
        #endregion

        #region Hoi Dap
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult HoiDap(string code, int? page)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            PaginatedList<Content> model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                var contents = contentRepository.GetListContentByParentCode(code, cultureInfo).OrderByDescending(b => b.ContentID);
                model = new PaginatedList<Content>(contents, page - 1 ?? 0, Constant.PageSize2);
                ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangHoiDap", new CultureInfo(cultureInfo))
                    + " - " + contentRepository.GetContentByCode(code, cultureInfo).ContentTitle;
            }

            ViewData["ParentCode"] = code;
            return View(model);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        public ActionResult ChiTietHoiDap(string code)
        {
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();

            Content model;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                model = contentRepository.GetContentByCode(code, cultureInfo);
                var parent = contentRepository.GetParentByContentCode(code, cultureInfo);
                ViewData["ParentTitle"] = parent.ContentTitle;
                ViewData["ParentCode"] = parent.ContentCode;
            }

            ViewData["PageTitle"] = ResourceUtil.Instance.GetString("TrangChiTietHoiDap", new CultureInfo(cultureInfo));
            return View(model);
        }
        #endregion

        #region Dat cau hoi
        [HttpPost()]
        public JsonResult DatCauHoi(string emailInfo)
        {
            try
            {
                string[] array = emailInfo.Split('~');

                try
                {
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress(array[1]);
                    mail.To.Add("nguyenthetrinh84@gmail.com");
                    mail.Subject = "Câu hỏi cần tư vấn từ website tanhungviet.com.vn";
                    mail.Body = "Đây là email tự động từ trang web tanhungviet.com.vn khi có khách hàng gửi câu hỏi tư vấn" + "\n" + "\n"
                        + "Thông tin khách hàng cần tư vấn : " + array[0] + "\n"
                        + "\t" + "Họ tên : " + array[0] + "\n"
                        + "\t" + "Địa chỉ email : " + array[1] + "\n"
                        + "\t" + "Số điện thoại : " + array[2] + "\n" + "\n"
                        + "Nội dung : " + "\n" + array[3];
                    mail.IsBodyHtml = false;

                    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                    string userName, password;
                    using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
                    {
                        ParameterRepository paramRepository = new ParameterRepository(entity);
                        userName = paramRepository.GetParamValue(Constant.ParamEmailAcc);
                        password = paramRepository.GetParamValue(Constant.ParamEmailPwd);
                    }
                    client.Credentials = new NetworkCredential(userName, password);
                    client.EnableSsl = true;
                    client.Send(mail);
                }
                catch (Exception e)
                {
                    return this.Json(new { mess = "Gửi câu hỏi thất bại. Xin thử lại sau." }, JsonRequestBehavior.AllowGet);
                }

                return this.Json(new { mess = "Gửi câu hỏi tư vấn thành công" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.Json(new { mess = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
        //RSS Feed
        public ActionResult RSS(string code)
        {
            string fullUrl = Request.Url.OriginalString;
            ViewData["DNS"] = fullUrl.Substring(0, fullUrl.IndexOf("/RSS"));

            string type = code.Substring(0, 1);
            string parentCode = code.Substring(1);
            string cultureInfo = "";
            if (Session["CultureInfo"] != null)
                cultureInfo = Session["CultureInfo"].ToString();
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                IEnumerable<TanHungViet.Web.Models.Content> contents = contentRepository.GetListContentByParentCode(parentCode, cultureInfo).OrderBy(b => b.ContentID);
                ListContent listContent = new ListContent();
                foreach (var item in contents)
                {
                    listContent.Items.Add(item);
                }
                if (type == "1")
                    return View("ChuyenMucTinTuc", listContent);
                else
                {
                    if (type == "2")
                        return View("ChuyenMucTuVan", listContent);
                    else
                        return View("ChuyenMucHoiDap", listContent);
                }
            }
        }
        #endregion

        #region Tim Kiem
        public ActionResult TimKiem(string code, int? page)
        {
            ViewData["Keyword"] = code;

            List<Content> listContent = null;
            using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
            {
                ContentRepository contentRepository = new ContentRepository(entity);
                listContent = contentRepository.GetListContentDetailByType("none").ToList<Content>();
            }

            //if (listContent == null)
            //    return View("Index");

            if (!string.IsNullOrEmpty(code))
            {
                int i = 0;
                do
                {
                    var item = listContent[i];
                    string titleSearch = TanHungViet.Helper.Util.GenerateCodeByTitle(code.ToLower());
                    if (!string.IsNullOrEmpty(item.ContentTitle))
                    {
                        string itemTitle = TanHungViet.Helper.Util.GenerateCodeByTitle(item.ContentTitle.ToLower());
                        if (itemTitle.Contains(titleSearch))
                        {
                            i++;
                            continue;
                        }
                    }

                    listContent.Remove(item);
                } while (i < listContent.Count);
            }

            for (int i = 0; i < listContent.Count; i++)
            {
                Content content = listContent[i];
                if (content.ContentParent == Constant.IDTinTuc
                    || content.ContentParent == Constant.IDTuVan
                    || content.ContentParent == Constant.IDHoiDap
                    || Constant.IDListDuAn.Contains(content.ContentParent))
                {
                    listContent.RemoveAt(i);
                    i--;
                }
            }

            int pageIndex = (page ?? 1) - 1;
            PaginatedList<Content> model = new PaginatedList<Content>(
                listContent.OrderByDescending(b => b.ContentID), pageIndex, Constant.PageSize);

            foreach (Content content in model)
            {
                if (content.ContentParent == Constant.IDBaoGia)
                {
                    content.ActionDetail = "BaoGia";
                    continue;
                }

                if (content.ContentParent == Constant.IDDichVu)
                {
                    content.ActionDetail = "DichVu";
                    continue;
                }

                if (content.ContentParent == Constant.IDGioiThieu)
                {
                    content.ActionDetail = "GioiThieu";
                    continue;
                }

                List<int> parentIDs = new List<int>();
                parentIDs.Add(Constant.IDTinTuc);
                using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
                {
                    ContentRepository contentRepository = new ContentRepository(entity);
                    List<int> temp = contentRepository.GetChildIDByParent(parentIDs);
                    if (temp.Contains(content.ContentParent))
                    {
                        content.ActionDetail = "ChiTietTinTuc";
                        continue;
                    }
                }

                parentIDs.Clear();
                parentIDs.Add(Constant.IDTuVan);
                using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
                {
                    ContentRepository contentRepository = new ContentRepository(entity);
                    List<int> temp = contentRepository.GetChildIDByParent(parentIDs);
                    if (temp.Contains(content.ContentParent))
                    {
                        content.ActionDetail = "ChiTietTuVan";
                        continue;
                    }
                }

                parentIDs.Clear();
                parentIDs.Add(Constant.IDHoiDap);
                using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
                {
                    ContentRepository contentRepository = new ContentRepository(entity);
                    List<int> temp = contentRepository.GetChildIDByParent(parentIDs);
                    if (temp.Contains(content.ContentParent))
                    {
                        content.ActionDetail = "ChiTietHoiDap";
                        continue;
                    }
                }

                using (DBTanHungVietEntities entity = new DBTanHungVietEntities())
                {
                    ContentRepository contentRepository = new ContentRepository(entity);
                    List<int> temp = contentRepository.GetChildIDByParent(Constant.IDListDuAn);
                    if (temp.Contains(content.ContentParent))
                    {
                        content.ActionDetail = "ChiTietDuAn";
                        continue;
                    }
                }
            }

            ViewData["CountResult"] = listContent.Count;
            return View("TimKiem", model);
        }
        #endregion
    }
}
